<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数字识别系统</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            text-align: center;
        }
        .upload-box {
            border: 2px dashed #ccc;
            padding: 20px;
            margin: 20px 0;
            border-radius: 5px;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 5px;
        }
        .preview-image {
            max-width: 300px;
            max-height: 300px;
            margin: 10px 0;
        }
        .btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .btn:hover {
            background-color: #45a049;
        }
        .error {
            color: red;
        }
        .prediction {
            font-size: 48px;
            font-weight: bold;
            color: #2c3e50;
        }
    </style>
</head>
<body>
    <h1>数字识别系统</h1>
    <p>上传包含数字(0-4)的图片，系统将识别数字</p>

    <form method="post" enctype="multipart/form-data">
        <div class="upload-box">
            <input type="file" name="file" accept="image/*" required>
            <br><br>
            <button type="submit" class="btn">上传并识别</button>
        </div>
    </form>

    {% if error %}
        <div class="error">{{ error }}</div>
    {% endif %}

    {% if prediction %}
        <div class="result">
            <h3>识别结果:</h3>
            <div class="prediction">{{ prediction }}</div>
            {% if image_path %}
                <img src="{{ url_for('static', filename='uploads/' + image_path.split('/')[-1]) }}"
                     alt="上传的图片" class="preview-image">
            {% endif %}
        </div>
    {% endif %}

    <div style="margin-top: 30px;">
        <h3>支持识别的数字:</h3>
        <p>0, 1, 2, 3, 4</p>
    </div>
</body>
</html>